#include "audio_sound.h"

using namespace krryn::audio;

sound::sound(input::ptr a_Input)
	: m_Input(a_Input), 
	  m_Volume(1), 
	  m_IsLooping(false) {};

void sound::set_volume(float a_Volume){
	m_Volume = a_Volume;
}

float sound::volume(){
	return m_Volume;
}

void sound::loop(bool a_Loop){
	m_IsLooping = a_Loop;
}

sample::ptr sound::next(int a_MilliSeconds){
	sample::ptr l_Sample = m_Input->next(a_MilliSeconds);

	if(l_Sample){
		l_Sample->set_volume(m_Volume);
	}
	
	if(m_IsLooping && (!more() || !l_Sample)){
		m_Input->reset();
	}

	return l_Sample;
}

void sound::reset(){
	m_Input->reset();
}

bool sound::more(){
	return m_Input->more();
}
